<?php 
global $header;
global $footer;
global $control;
global $message;
global $serial, $terms, $definitions, $count, $error;
global $glossary;

global $featureManager;
$header['title'] = $glossary['abbr'] != ""?$glossary['abbr']:$glossary['title'];
$header['head'] = '
<script type="text/javascript" src="'.RESOURCE_BASE.'glossary/base.js"></script>
';
$header['intro'] = '<em class="title">'.$glossary['title'].'</em>';
$featureManager->apply("com.yizin.platform.site.header", $header);
$featureManager->apply("com.yizin.platform.site.footer", $footer);
$featureManager->apply("com.yizin.platform.site.control", $control);

if(count($terms) == 0) $isget = TRUE;
?>
<?= $header['html']?>
<div class="container-L">
	<?=$control['html']?>
</div>
<div class="container-R">
	<?=Utils::showMessage($message)?>
	<?=Utils::loadSegment(dirname(__FILE__)."/segments/_s_glossary_toolbar_.php")?>
	<form action="<?=REQUEST_BASE?>glossary/<?=$serial?>/addterms/" method="post">
		<table class="addterms">
			<col width="20" />
			<col width="200"/>
			<col width="400"/>
			<thead>
				<tr>
					<th></th>
					<th scope="col">Term</th>
					<th scope="col">Definition</th>
				</tr>
			</thead>
			<?php if($isget) { ?>
				<tr>
					<th scope="row">1.</th>
					<td><input type="text" name="terms[]" class="text" /></td>
					<td><textarea rows="3" class="text" name="definitions[]"></textarea></td>
				</tr>
			<?php } else if($count == 1) { ?>
				<tr>
					<th scope="row">1.</th>
					<td>
						<input type="text" name="terms[]" value="<?=$terms[0]?>" class="text" />
						<?=Utils::showFormError($error[0])?>
					</td>
					<td><textarea rows="3" class="text" name="definitions[]"><?=$definitions[0]?></textarea></td>
				</tr>
			<?php } else for($i = 0;$i < $count;$i++) { ?>
			<tr>
				<th scope="row"><?=$i+1?>.</th>
				<td>
					<input type="text" name="terms[]" value="<?=$terms[$i]?>" class="text" />
					<a href="#" class="remove" onclick="glossary.removeterm(this);return false;">Remove this term</a>
					<?=Utils::showFormError($error[$i])?>
				</td>
				<td><textarea rows="3" class="text" name="definitions[]"><?=$definitions[$i]?></textarea></td>
				<script type="text/javascript">
					$(function(){
						window.glossary.is_first_tr_added_remove = true;
					})
				</script>
			</tr>
			<?php } ?>
			<tr>
				<th></th>
				<td colspan="2">
					<a class="add" href="#" onclick="glossary.addterms(this);return false;">Add one more</a>
					<div class="vspacing-tall"></div>
					<input type="submit" value="Submit" class="button" />
				</td>
			</tr>
		</table>
	</form>
</div>
<?= $footer['html']?>
